*TROOP DEPLOYMENT AND PUBLIC OPINION
*FLYNN, MARTINEZ MACHAIN, AND STOYAN
*FILE CREATED BY ALISSANDRA STOYAN ON 2017.01.30
*LAST UPDATED BY ALISSANDRA STOYAN ON 2017.02.06
*LAST UPDATED BY MICHAEL FLYNN ON 2017.02.08
*LAST UPDATED BY ALISSANDRA STOYAN ON 2017.02.09
*LAST UPDATED BY MICHAEL FLYNN ON 2017.02.12
*LAST UPDATED BY ALISSANDRA STOYAN ON 2017.02.15
*LAST UPDATED BY MICHAEL FLYNN ON 2017.02.16
*LAST UPDATED BY ALISSANDRA STOYAN ON 2017.02.27
*LAST UPDATED BY ALISSANDRA STOYAN ON 2017.02.28
*LAST UPDATED BY ALISSANDRA STOYAN ON 2017.03.16
*LAST UPDATED BY MICHAEL FLYNN ON 2017.03.17
*LAST UPDATED BY ALISSANDRA STOYAN ON 2017.06.29
*LAST UPDATED BY MICHAEL FLYNN ON 2018.01.05
*LAST UPDATED BY MICHAEL FLYNN ON 2018.01.22
*LAST UPDATED BY ALISSANDRA STOYAN ON 2018.02.05

********************************

use "1257201564Peru LAPOP AmericasBarometer 2014 v3.0_W.dta", clear
cd ""
*use "~/Dropbox/Projects/Troops and Public Opinion in Latin America/Data/Raw Data/LAPOP/Peru/1257201564Peru LAPOP AmericasBarometer 2014 v3.0_W.dta", clear
*cd "~/Dropbox/Projects/Troops and Public Opinion in Latin America/Tables"

set scheme plotplainblind

*use "C:\Users\carlamm\Dropbox\Working Papers\Troops and Public Opinion in Latin America\Data\Raw Data\LAPOP\Peru\1257201564Peru LAPOP AmericasBarometer 2014 v3.0_W.dta" , clear
*cd "C:\Users\carlamm\Dropbox\Working Papers\Troops and Public Opinion in Latin America\Tables"

********************************
*IDENTIFYING LAPOP VARIABLES OF INTEREST AND CONFIRMING OBSERVATIONS
********************************

*log using "keyvariables", text replace
set more off

*Opinions of the U.S. in general
*Most influence in Lat Am? (4) = U.S.
tab for1n
*In 10 years who will have most influence? (4) = U.S.
tab for4
*Model of development for our future? (4) = U.S.
tab for5
*How much influence does the U.S. have in our country?
tab for6b
*U.S. influence is very positive/positive/negative/very negative?
tab for7b
*The U.S. government is very/somewhat/a little/not at all trustworthy?
tab mil10e

*Political Knowledge of the U.S.
*What is the name of the current U.S. President?
tab gi1

*Opinions of the Peruvian Military
*How much confidence do you have in the Armed Forces?
tab b12
*To what extent do you think that the Peruvian Armed Forces respect Peruvian citizens' human rights today?
tab b3milx

*Opinions of the U.S. Military
*To what extent do you trust the U.S. Armed Forces?
tab mil3
*To what extent should the U.S. Armed Forces work with the Peruvian Armed Forces to improve national security?
tab mil4

*Satisfaction with President Humala
tab m1

*Satisfaction with infrastructure, schools, and public health
tab sd2new2
tab sd3new2
tab sd6new2

*National economic situation
tab soct2
*Personal economic situation
tab idio2

*log close


********************************
*GENERATING KEY CONTROL VARIABLES
********************************

*SOCIOECONOMIC STATUS
/*Scale measuring household well-being based on
ownership of *14* consumer durables. Scale is constructed
by weighting each item according to its prevalence in the
country, with more prevalent items carrying less weight.
Higher values indicate higher SES.*/
*Weight calculated by 100-%withGood)

gen r5o = .
replace r5o=0 if r5==0
replace r5o=1 if r5==1 | r5==2 | r5==3

set more off
tab r1
*ANY TYPE OF TV - 6.55
tab r3
*REFRIGERATOR - 35.00
tab r4
*TELEPHONE - 61.24
tab r4a
*CELL PHONE - 16.28
tab r5o
*VEHICLE - 85.86
tab r6
*WASHING MACHINE - 65.33
tab r7
*MICROWAVE - 69.07
tab r8
*MOTORCYCLE - 82.97
tab r12
*POTABLE WATER - 10.27
tab r14
*BATHROOM - 14.61
tab r15
*COMPUTER - 56.22
tab r16
*FLAT SCREEN TV - 62.67
tab r18
*INTERNET - 65.26
tab r26
*CONNECTED TO SEWER SYSTEM - 13.28

gen ses=.
replace ses = ((r1*6.55) + (r3*35.00) + (r4*61.24) + (r4a*16.28) + (r5o*85.86) + (r6*65.33) + (r7*69.07) + (r8*82.97) + (r12*10.27) + (r14*14.61) + (r15*56.22) + (r16*62.67) + (r18*65.26) + (r26*13.28))/25.7844

alpha r1 r3 r4 r4a r5o r6 r7 r8 r12 r14 r15 r16 r26, asis
*scale reliability coefficient = 0.7859

*AGE
gen q2sq=q2*q2

*LANGUAGE
gen lang=.
replace lang=0 if leng1==1101
replace lang=1 if leng1>=1102
label define labellang 0 "Spanish" 1 "Other"
label values lang labellang

*EDUCATION
gen edsc=ed
recode edsc 1/5=1 6/8=2 9/11=3 12=4 13/15=5 16=6 17/18=7
label define labeleduc 0 "None" 1 "Primary, 1st-5th Grade" 2 "Primary, 6th-8th Grade" 3 "Incomplete Secondary" 4 "Complete Secondary" 5 "Incomplete University" 6 "Complete University" 7 "Graduate School"
label values edsc labeleduc

*REMITTANCES
gen remit=2-q10a
label define labelremit 0 "no" 1 "yes"
label values remit labelremit

*URBAN/RURAL
gen urban1=2-ur
label define labelurban1 0 "rural" 1 "urbano"
label values urban1 labelurban1

gen urban2=5-tamano
label define labelurban2 0 "Area rural" 1 "Ciudad pequena" 2 "Ciudad mediana" 3 "Ciudad grande" 4 "Capital Nacional (area metropolitana)"
label values urban2 labelurban2

*IDEOLOGY (LEFT=0, RIGHT=10)
*fine as coded

*PRESIDENTIAL APPROVAL
gen presapproval=5-m1
label define labelpresapproval 0 "Muy malo (pesimo)" 1 "Malo" 2 "Ni bueno ni malo" 3 "Bueno" 4 "Muy bueno"
label values presapproval labelpresapproval

*OPINION ABOUT CHINA
gen chgovtrust=.
replace chgovtrust=4-mil10a
label define labels3 0 "not at all trustworthy" 1 "a little trustworthy" 2 "somewhat trustworthy" 3 "very trustworthy"
label values chgovtrust labels3

*CHINESE INFLUENCE - AMOUNT AND CHARACTER
gen for6_new = 4-for6
label define labels1 0 "none" 1 "a little" 2 "some" 3 "a lot"
label values for6_new labels1

gen for7_new=.
replace for7_new=-2 if for7==5
replace for7_new=-1 if for7==4
replace for7_new=0 if for7==3
replace for7_new=1 if for7==2
replace for7_new=2 if for7==1

gen chinfl_peru = .
replace chinfl_peru = for6_new*for7_new if for6_new!=. & for7_new!=.
label define labels2 -6 "a lot/v. neg" -4 "some/v. neg" -3 "a lot/neg." -2 "a little/v. neg or some/neg" -1 "a little/neg" 0 "none/neutral" 1 "a little/pos" 2 "a little/v. pos or some/pos" 3 "a lot/pos" 4 "some/v. pos" 6 "a lot/v. pos"
label values chinfl_peru labels2

*OPINION ABOUT IRAN
gen irgovtrust=.
replace irgovtrust=4-mil10c
*label define labels3 0 "not at all trustworthy" 1 "a little trustworthy" 2 "somewhat trustworthy" 3 "very trustworthy"
label values irgovtrust labels3

*SATISFACTION MEASURES
gen satinfra=.
replace satinfra=4-sd2new2
label define labelssat 0 "Very Unsatisfied" 1 "Unsatisfied" 2 "Satisfied" 3 "Very Satisfied"
label values satinfra labelssat

gen satedu=.
replace satedu=4-sd3new2
label values satedu labelssat

gen satmed=.
replace satmed=4-sd6new2
label values satmed labelssat

*TRUST IN GOVERNMENT INSTITUTIONS
*ADDITIVE TRUST_I
gen trust_i=b1+b11+b13+b17+b21a
alpha b1 b11 b13 b17 b21a

*POLYCHORIC FACTOR ANALYSIS
*mean-centering variables
gen b1_c = b1 - 3.261138
gen b11_c = b11 - 3.813179 
gen b13_c = b13 - 2.644159
gen b17_c = b17 - 3.807273 
gen b21a_c = b21a - 3.329293

polychoric b1_c b11_c b13_c b17_c b21a_c
display r(sum_w)
global N = r(sum_w)
matrix r = r(R)
factormat r, n($N) factors(3)
rotate, promax
predict trust_f

*SOCIOTROPIC VIEWS OF THE ECONOMY
gen sociotrop=.
replace sociotrop=-1 if soct2==3
replace sociotrop=0 if soct2==2
replace sociotrop=1 if soct2==1
label define labelssociotrop -1 "Worse" 0 "Same" 1 "Better"
label values sociotrop labelssociotrop

*INTERPERSONAL TRUST
gen iptrust=4-it1
label define labelsiptrust 0 "Not at all trustworthy" 1 "A little trustworthy" 2 "Somewhat trustworthy" 3 "Very trustworthy"
label values iptrust labelsiptrust

*AZPURU 2016
*POLITICAL INTEREST - FREQUENCY OF FOLLOWING THE NEWS
gen polint=5-gi0
label define labelspolint 0 "Never" 1 "Rarely" 2 "Several times a month" 3 "Several times a week" 4 "Daily"
label values polint labelspolint

*AZPURU & BONIFACE 2015
*PERCEPTIONS OF INSECURITY
tab aoj11

*NATIONALISM (PRIDE) - orgullo por el sistema politico
tab b4

*******************************
*GENERATING REGIONAL VIOLENCE MEASURE FROM PERU'S TRUTH AND RECONCILIATION COMMISSION
*2003 REPORT, TABLE 2, PERU 1980-2000: CANITDAD DE MUERTOS Y DESAPARECIDOS REPORTADOS 
*A LA CVR SEGUN DEPARTAMENTO EN EL QUE OCURRIERON LOS HECHO POR PRESUNTO RESPONSABLE GRUPAL
*I AM USING TOTAL NUMBERS, REGARDLESS OF WHO PERPETRATED THE VIOLENCE (SENDERO ONLY AND STATE ONLY CORRELATE AT 0.95 OR ABOVE)
*******************************

gen violence=.
replace violence=21 if prov==1101
replace violence=220 if prov==1102
replace violence=1022 if prov==1103
replace violence=16 if prov==1104
replace violence=10661 if prov==1105
replace violence=51 if prov==1106
replace violence=49 if prov==1107
replace violence=361 if prov==1108
replace violence=1681 if prov==1109
replace violence=2350 if prov==1110
replace violence=50 if prov==1111
replace violence=2565 if prov==1112
replace violence=71 if prov==1113
replace violence=23 if prov==1114
replace violence=466 if prov==1115
replace violence=54 if prov==1116
replace violence=251 if prov==1119
replace violence=83 if prov==1120
replace violence=423 if prov==1121
replace violence=853 if prov==1122
replace violence=2 if prov==1123
replace violence=412 if prov==1125

********************************
*GENERATING TROOP DEPLOYMENT GEOGRAPHIC VARIABLES
********************************

*ALL TIME - DEPARTMENT/REGION DUMMY (1 if U.S. Troops)
gen ustd_d=0
replace ustd_d=1 if prov==1113 | prov==1114 | prov==1115 | prov==1120 | prov==1111 | prov==1109 | prov==1105
replace ustd_d=1 if perprov==1501

*TWO-YEAR - SINCE 2012 DEPARTMENT/REGION DUMMY (1 if U.S. Troops in last 2 years)
gen ustd_d2=0
replace ustd_d2=1 if prov==1111 | prov==1109 | perprov==1501

*FOUR-YEAR - Since 2010 DEPARTMENT/REGION DUMMY (1 if U.S. Troops in last 4 years)
gen ustd_d4=0
replace ustd_d4=1 if prov==1111 | prov==1109 | perprov==1501 | prov== 1120 

*SIX-YEAR - Since 2008 DEPARTMENT/REGION DUMMY (1 if U.S. Troops in last 6 years)
gen ustd_d6=0
replace ustd_d6=1 if prov==1111 | prov==1109 | perprov==1501 | prov== 1120 | prov == 1105


*ALL TIME - PROVINCE DUMMY (1 if U.S. Troops)
gen ustd_p=0
replace ustd_p=1 if perprov==1201 | perprov==1508 | perprov==1102 | perprov==901 | perprov==906 | perprov==1101 | perprov==1501 | perprov==501 | perprov==1403 

*TWO-YEAR - SINCE 2012 PROVINCE DUMMY (1 if U.S. Troops in last 2 years)
gen ustd_p2=0
replace ustd_p2=1 if perprov==1102 | perprov==901 | perprov==906 | perprov==1101 | perprov==1501

*FOUR-YEAR - SINCE 2010 PROVINCE DUMMY (1 if U.S. Troops in last 4 years)
gen ustd_p4=0
replace ustd_p4=1 if perprov==1102 | perprov==901 | perprov==906 | perprov==1101 | perprov==1501 

*SIX-YEAR - SINCE 2008 PROVINCE DUMMY (1 if U.S. Troops in last 6 years)
gen ustd_p6=0
replace ustd_p6=1 if perprov==1102 | perprov==901 | perprov==906 | perprov==1101 | perprov==1501 | perprov==1508 | perprov==501 




*DEPARTMENT/REGION COUNT
gen ustd_dc=0
replace ustd_dc=1 if prov==1113 | prov==1115 | prov==1120 | prov==1105
replace ustd_dc=2 if perprov==1501 | prov==1109
replace ustd_dc=3 if prov==1111





********************************
*RECODING POTENTIAL VARS OF INTEREST
********************************

*US INFLUENCE
gen usinfl_la=0
replace usinfl_la=1 if for1n==4

gen usinfl_la_f=0
replace usinfl_la_f=1 if for4==4

corr usinfl_la usinfl_la_f
corr usinfl_la_f ustd_d

*US MODEL OF DEVELOPMENT
gen usmoddev=0
replace usmoddev=1 if for5==4

corr usmoddev ustd_p2

corr ustd_p for6b
corr ustd_d for7b

*US INFLUENCE - AMOUNT AND CHARACTER
gen for6b_new = 4-for6b
*label define labels1 0 "none" 1 "a little" 2 "some" 3 "a lot"
label values for6b_new labels1

gen for7b_new=.
replace for7b_new=-2 if for7b==5
replace for7b_new=-1 if for7b==4
replace for7b_new=0 if for7b==3
replace for7b_new=1 if for7b==2
replace for7b_new=2 if for7b==1

gen usinfl_peru = .
replace usinfl_peru = for6b_new*for7b_new if for6b_new!=. & for7b_new!=.
*label define labels2 -6 "a lot/v. neg" -4 "some/v. neg" -3 "a lot/neg." -2 "a little/v. neg or some/neg" -1 "a little/neg" 0 "none/neutral" 1 "a little/pos" 2 "a little/v. pos or some/pos" 3 "a lot/pos" 4 "some/v. pos" 6 "a lot/v. pos"
label values usinfl_peru labels2

corr ustd_d usinfl_peru
corr ustd_p usinfl_peru

*The U.S. government is very/somewhat/a little/not at all trustworthy?
tab mil10e

gen usgovtrust=.
replace usgovtrust=4-mil10e
*label define labels3 0 "not at all trustworthy" 1 "a little trustworthy" 2 "somewhat trustworthy" 3 "very trustworthy"
label values usgovtrust labels3

corr ustd_d usgovtrust
corr ustd_p usgovtrust

*Opinions of the Peruvian Military
*How much confidence do you have in the Armed Forces?
tab b12

corr ustd_d b12
corr ustd_p b12

*To what extent do you think that the Peruvian Armed Forces respect Peruvian citizens' human rights today?
tab b3milx

corr ustd_d b3milx
corr ustd_p b3milx

*Opinions of the U.S. Military
*To what extent do you trust the U.S. Armed Forces?
tab mil3

corr ustd_d mil3
corr ustd_p mil3

*To what extent should the U.S. Armed Forces work with the Peruvian Armed Forces to improve national security?
tab mil4

corr ustd_d mil4
corr ustd_p mil4

*DESCRIPTIVE STATISTICS
su mil3 usgovtrust usinfl_peru ustd_d ustd_d2 q2 ses edsc lang urban1 l1 b12 trust_f presapproval remit satinfra

********************************
*SECONDARY ANALYSES - 2.6.2017
********************************
set more off

********************
*SUMMARY STATISTICS*
********************
set more off
label var mil3 "Trust in U.S. Military"
label var usgovtrust "Trust in U.S. Government"
label var usinfl_peru "U.S. Influence in Peru"
label var ustd_d "Exposure to U.S. Deployment"
label var ustd_d2 "Exposure to U.S. Deployment (2 Years)"
label var ustd_d4 "Exposure to U.S. Deployment (4 Years)"
label var ustd_d6 "Exposure to U.S. Deployment (6 Years)"
label var ustd_p "Exposure to U.S. Deployment"
label var ustd_p2 "Exposure to U.S. Deployment (2 Years)"
label var ustd_p6 "Exposure to U.S. Deployment (6 Years)"
label var q1 "Sex"
label var q2 "Age"
label var ses "Socioeconomic Status"
label var edsc "Education"
label var lang "Non-Spanish Speaker"
label var urban1 "Urban"
label var l1 "Ideology"
label var eff2 "Efficacy"
label var b4 "Nationalism"
label var aoj11 "Perception of Insecurity"
label var presapproval "Presidential Approval"
label var remit "Remittances"
label var satinfra "Satisfaction with Infrastructure"
label var b12 "Peruvian Military Trust"
label var trust_f "Peruvian Government Trust"
label var iptrust "Interpersonal Trust"
label var sociotrop "Satisfaction with Country's Economic Situation"
label var satmed "Satisfaction with Healthcare Services"
label var satedu "Satisfaction with Public Schools"
label var ustd_dc "Deployment Count"
label var polint "Political Interest"
label var violence "Violence"

sutex2 mil3 usgovtrust usinfl_peru ustd_d ustd_d2 ustd_d4 ustd_d6 q2 ses edsc lang urban1 remit eff2 l1 presapproval b12 trust_f iptrust b4 aoj11 satinfra violence, ///
digits(3) minmax varlab tabular ///
caption("Summary Statistics") tablabel(tab:sumstat) saving(table_sumstats) placement("t") replace

*****************
*REPORTED MODELS*
*****************
*Added several controls from Azpuru (2017) and Azpuru and Boniface (2015)
*efficacy (eff2), insecurity (aoj11), nationalism/pride in the Peruvian political system (b4)

*US MILITARY TRUST
ologit mil3 ustd_d q2 ses edsc lang urban1 l1 eff2 b12 b4 aoj11 presapproval remit satinfra violence
est store m1a
ologit mil3 ustd_d2 q2 ses edsc lang urban1 l1 eff2 b12 b4 aoj11 presapproval remit satinfra violence
est store m1b
ologit mil3 ustd_d4 q2 ses edsc lang urban1 l1 eff2 b12 b4 aoj11 presapproval remit satinfra violence
est store m1c
ologit mil3 ustd_d6 q2 ses edsc lang urban1 l1 eff2 b12 b4 aoj11 presapproval remit satinfra violence
est store m1d
*IV = COUNT OF DEPLOYMENTS
ologit mil3 ustd_dc q2 ses edsc lang urban1 l1 eff2 b12 b4 aoj11 presapproval remit satinfra violence

*US GOVERNMENT TRUST
ologit usgovtrust ustd_d q2 ses edsc lang urban1 l1 eff2 trust_f b4 aoj11 presapproval remit satinfra violence
est store m2a
ologit usgovtrust ustd_d2 q2 ses edsc lang urban1 l1 eff2 trust_f b4 aoj11 presapproval remit satinfra violence
est store m2b
ologit usgovtrust ustd_d4 q2 ses edsc lang urban1 l1 eff2 trust_f b4 aoj11 presapproval remit satinfra violence
est store m2c
ologit usgovtrust ustd_d6 q2 ses edsc lang urban1 l1 eff2 trust_f b4 aoj11 presapproval remit satinfra violence
est store m2d
*IV = COUNT OF DEPLOYMENTS
ologit usgovtrust ustd_dc q2 ses edsc lang urban1 l1 eff2 trust_f b4 aoj11 presapproval remit satinfra violence

*US INFLUENCE
regress usinfl_peru ustd_d q2 ses edsc lang urban1 l1 eff2 trust_f aoj11 presapproval remit satinfra violence
est store m3a
regress usinfl_peru ustd_d2 q2 ses edsc lang urban1 l1 eff2 trust_f aoj11 presapproval remit satinfra violence
est store m3b
regress usinfl_peru ustd_d4 q2 ses edsc lang urban1 l1 eff2 trust_f aoj11 presapproval remit satinfra violence
est store m3c
regress usinfl_peru ustd_d6 q2 ses edsc lang urban1 l1 eff2 trust_f aoj11 presapproval remit satinfra violence
est store m3d
*IV = COUNT OF DEPLOYMENTS
regress usinfl_peru ustd_dc q2 ses edsc lang urban1 l1 eff2 trust_f aoj11 presapproval remit satinfra violence

foreach v of varlist * {
	label variable `v' `"\hspace{0.2cm} `: variable label `v''"'
	}

	
* Main Table: Trust in US military
#delimit ;
	esttab m1a m1b m1c m1d using Table_1_20180124.tex, replace 
	scalars("ll log-likelihood")  
	nodep
	bic
	wide
	se(2) 
	b(2) 
	obslast 
	nonumbers
	mtitles("1A" "1B" "1C" "1D")
	eqlabel(none) 
	coeflabel(_cons "\hspace{0.2cm} Constant")
	mgroups("Trust in U.S. Military", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))
	nogaps 
	label
	noomitted
	refcat(ustd_d "\emph{Key Independent Variables}", nolabel)
	star(* 0.10 ** 0.05 *** 0.01)  
	compress
	keep(ustd_d ustd_d2 ustd_d4 ustd_d6)
	order(ustd_d ustd_d2 ustd_d4 ustd_d6)
	nonotes 
	nobaselevels
	addnote("Two-tailed significance tests used." "$*$ p$\leq$ 0.10; $**$ p$\leq$ 0.05; $***$ p$\leq$0.01") 
	;		
	
	#delimit cr	
	
* Main Table: Trust in US government
#delimit ;
	esttab m2a m2b m2c m2d using Table_2_20180124.tex, replace 
	scalars("ll log-likelihood")  
	nodep
	bic
	wide
	se(2) 
	b(2) 
	obslast 
	nonumbers
	mtitles("2A" "2B" "2C" "2D")
	eqlabel(none) 
	coeflabel(_cons "\hspace{0.2cm} Constant")
	mgroups("Trust in U.S. Government", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))
	nogaps 
	label
	noomitted
	refcat(ustd_d "\emph{Key Independent Variables}", nolabel)
	star(* 0.10 ** 0.05 *** 0.01)  
	compress
	keep(ustd_d ustd_d2 ustd_d4 ustd_d6)
	order(ustd_d ustd_d2 ustd_d4 ustd_d6)
	nonotes 
	nobaselevels
	addnote("Two-tailed significance tests used." "$*$ p$\leq$ 0.10; $**$ p$\leq$ 0.05; $***$ p$\leq$0.01") 
	;		
	
	#delimit cr
	
* Main Table: Assessment of US government influence
#delimit ;
	esttab m3a m3b m3c m3d using Table_3_20180124.tex, replace 
	scalars("r2 R$^2$")  
	nodep
	wide
	se(2) 
	b(2) 
	obslast 
	nonumbers
	mtitles("3A" "3B" "3C" "3D")
	eqlabel(none) 
	coeflabel(_cons "\hspace{0.2cm} Constant")
	mgroups("Assessment of U.S. Influence", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))
	nogaps 
	label
	noomitted
	refcat(ustd_d "\emph{Key Independent Variables}", nolabel)
	star(* 0.10 ** 0.05 *** 0.01)  
	compress
	keep(ustd_d ustd_d2 ustd_d4 ustd_d6)
	order(ustd_d ustd_d2 ustd_d4 ustd_d6)
	nonotes 
	nobaselevels
	addnote("Two-tailed significance tests used." "$*$ p$\leq$ 0.10; $**$ p$\leq$ 0.05; $***$ p$\leq$0.01") 
	;		
	
	#delimit cr	

	
* Appendix Table: Trust in US military (full)
#delimit ;
	esttab m1a m1b m1c m1d using Table_Appendix_Full_1_20180124.tex, replace 
	scalars("ll log-likelihood")  
	nodep
	bic
	wide
	se(2) 
	b(2) 
	obslast 
	nonumbers
	mtitles("1A" "1B" "1C" "1D")
	eqlabel(none) 
	coeflabel(_cons "\hspace{0.2cm} Constant")
	mgroups("Trust in U.S. Military", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))
	nogaps 
	label
	noomitted
	refcat(ustd_d "\emph{Key Independent Variables}" q2 "\emph{Demographic Variables}" l1 "\emph{Attitudinal Variables}", nolabel)
	star(* 0.10 ** 0.05 *** 0.01)  
	compress
	order(ustd_d ustd_d2 ustd_d4 ustd_d6 q2 ses edsc lang urban1 remit eff2 l1 presapproval b12 trust_f b4 aoj11 satinfra _cons)
	nonotes 
	nobaselevels
	addnote("Two-tailed significance tests used." "$*$ p$\leq$ 0.10; $**$ p$\leq$ 0.05; $***$ p$\leq$0.01") 
	;		
	
	#delimit cr	
	
* Appendix Table: Trust in US government (full)
#delimit ;
	esttab m2a m2b m2c m2d using Table_Appendix_Full_2_20180124.tex, replace 
	scalars("ll log-likelihood")  
	nodep
	bic
	wide
	se(2) 
	b(2) 
	obslast 
	nonumbers
	mtitles("2A" "2B" "2C" "2D")
	eqlabel(none) 
	coeflabel(_cons "\hspace{0.2cm} Constant")
	mgroups("Trust in U.S. Government", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))
	nogaps 
	label
	noomitted
	refcat(ustd_d "\emph{Key Independent Variables}" q2 "\emph{Demographic Variables}" l1 "\emph{Attitudinal Variables}", nolabel)
	star(* 0.10 ** 0.05 *** 0.01)  
	compress
	order(ustd_d ustd_d2 ustd_d4 ustd_d6 q2 ses edsc lang urban1 remit eff2 l1 presapproval b12 trust_f b4 aoj11 satinfra _cons)
	nonotes 
	nobaselevels
	addnote("Two-tailed significance tests used." "$*$ p$\leq$ 0.10; $**$ p$\leq$ 0.05; $***$ p$\leq$0.01") 
	;		
	
	#delimit cr
	
* Appendix Table: Assessment of US government influence (full)
#delimit ;
	esttab m3a m3b m3c m3d using Table_Appendix_Full_3_20180124.tex, replace 
	scalars("r2 R$^2$")  
	nodep
	wide
	se(2) 
	b(2) 
	obslast 
	nonumbers
	mtitles("3A" "3B" "3C" "3D")
	eqlabel(none) 
	coeflabel(_cons "\hspace{0.2cm} Constant")
	mgroups("Assessment of U.S. Influence", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))
	nogaps 
	label
	noomitted
	refcat(ustd_d "\emph{Key Independent Variables}" q2 "\emph{Demographic Variables}" l1 "\emph{Attitudinal Variables}", nolabel)
	star(* 0.10 ** 0.05 *** 0.01)  
	compress
	order(ustd_d ustd_d2 ustd_d4 ustd_d6 q2 ses edsc lang urban1 remit eff2 l1 presapproval b12 trust_f b4 aoj11 satinfra _cons)
	nonotes 
	nobaselevels
	addnote("Two-tailed significance tests used." "$*$ p$\leq$ 0.10; $**$ p$\leq$ 0.05; $***$ p$\leq$0.01") 
	;		
	
	#delimit cr	
	
	
* Coefficient equality test
	suest m1a m1b
	test [m1a_mil3]ustd_d = [m1b_mil3]ustd_d2
	suest m2a m2b
	test [m2a_usgovtrust]ustd_d = [m2b_usgovtrust]ustd_d2
	suest m3a m3b
	test [m3a_mean]ustd_d = [m3b_mean]ustd_d2


* All time
* Predicted Probability - US Military Trust Y=6 + Y=7

		ologit mil3 i.ustd_d q2 ses edsc lang urban1 l1 b12 presapproval remit satinfra
		
		sum ustd_d if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d=(0 1) (means) _all lang=0 urban1=1 remit=0 ) expression(predict(outcome(6))+predict(outcome(7))) level(95) contrast post
		est store m1
	
* Predicted Probability - US Government Trust Y=3

		ologit usgovtrust i.ustd_d q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra
		
		sum ustd_d if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d=(0 1) (means) _all lang=0 urban1=1 remit=0 ) predict(outcome(3)) level(95) contrast post
		est store m2
			
		
* Predicted Value - US Influence

		reg usinfl_peru i.ustd_d q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra
		
		sum ustd_d if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d=(0 1) (means) _all lang=0 urban1=1 remit=0 ) predict(xb) level(95) contrast post
		est store m3


* Two-Year Window
* Predicted Probability - US Military Trust Y=6 + Y=7

		ologit mil3 i.ustd_d2 q2 ses edsc lang urban1 l1 b12 presapproval remit satinfra
		
		sum ustd_d2 if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d2=(0 1) (means) _all lang=0 urban1=1 remit=0 ) expression(predict(outcome(6))+predict(outcome(7))) level(95) contrast post
		est store m4
		
	
* Predicted Probability - US Government Trust Y=3

		ologit usgovtrust i.ustd_d2 q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra
		
		sum ustd_d2 if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d2=(0 1) (means) _all lang=0 urban1=1 remit=0 ) predict(outcome(3)) level(95) contrast post
		est store m5

		
* Predicted Value - US Influence

		reg usinfl_peru i.ustd_d2 q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra
		
		sum ustd_d2 if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d2=(0 1) (means) _all lang=0 urban1=1 remit=0 ) predict(xb) level(95) contrast post
		est store m6
		

* Four-Year Window
* Predicted Probability - US Military Trust Y=6 + Y=7

		ologit mil3 i.ustd_d4 q2 ses edsc lang urban1 l1 b12 presapproval remit satinfra
		
		sum ustd_d4 if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d4=(0 1) (means) _all lang=0 urban1=1 remit=0) expression(predict(outcome(6))+predict(outcome(7))) level(95) contrast post
		est store m7
			
		
* Predicted Probability - US Government Trust Y=3

		ologit usgovtrust i.ustd_d4 q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra
		
		sum ustd_d4 if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d4=(0 1) (means) _all lang=0 urban1=1 remit=0 ) predict(outcome(3)) level(95) contrast post
		est store m8
			
		
* Predicted Value - US Influence

		reg usinfl_peru i.ustd_d4 q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra
		
		sum ustd_d4 if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d4=(0 1) (means) _all lang=0 urban1=1 remit=0 ) predict(xb) level(95) contrast post
		est store m9

		
* Six-Year Window
* Predicted Probability - US Military Trust Y=6 + Y=7

		ologit mil3 i.ustd_d6 q2 ses edsc lang urban1 l1 b12 presapproval remit satinfra
		
		sum ustd_d6 if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d6=(0 1) (means) _all lang=0 urban1=1 remit=0 ) expression(predict(outcome(6))+predict(outcome(7))) level(95) contrast post
		est store m10
		
		
* Predicted Probability - US Government Trust Y=3

		ologit usgovtrust i.ustd_d6 q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra
		
		sum ustd_d6 if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d6=(0 1) (means) _all lang=0 urban1=1 remit=0 ) predict(outcome(3)) level(95) contrast post
		est store m11
		
		
* Predicted Value - US Influence

		reg usinfl_peru i.ustd_d6 q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra
		
		sum ustd_d6 if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d6=(0 1) (means) _all lang=0 urban1=1 remit=0 ) predict(xb) level(95) contrast post
		est store m12
		
		
* Combine graphs into single figure		
		
	coefplot m1 m4 m7 m10, ///
	drop(q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra) ///
	levels(95) ///
	vertical ///
	m(O) ///
	title("A" "US Military Trust") ///
	eqlabels("All" "Two-Year") 	///
	ytitle("Pr(High or Very High Trust)") ///
	ylabel(.05(.02).21) ///
	xlabel(1 "No Deployment" 2 "Deployment") ///
	name(panel1, replace)
	
	coefplot m2 m5 m8 m11, ///
	drop(q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra) ///
	levels(95) ///
	vertical ///
	m(O) ///
	title("B" "US Government Trust") ///
	eqlabels("All" "Two-Year") 	///
	ytitle("Pr(Very Trustworthy)") ///
	ylabel(.05(.02).21) ///
	xlabel(1 "No Deployment" 2 "Deployment") ///
	name(panel2, replace)
	
	coefplot (m3, label(All Years)) (m6, label(Two Years)) (m9, label(Four Years)) (m12, label(Six Years)), ///
	drop(q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra) ///
	levels(95) ///
	vertical ///
	m(O) ///
	title("C" "US Influence") ///
	eqlabels("All" "Two-Year") 	///
	ytitle("Assessment of U.S. Influence") ///
	ylabel(#9) ///
	xlabel(1 "No Deployment" 2 "Deployment") ///
	legend(cols(4)) ///
	name(panel3, replace)
	
	cd ""
	*cd "C:\Users\stoyan\Dropbox\Troops and Public Opinion in Latin America\Figures"
	
	grc1leg panel1 panel2 panel3, leg(panel3) pos(11) cols(3) title("United States HCA Deployments and Mass Attitudes", pos(11)) b1("Department Exposure to Treatment", size(small)) imargin(b=3 r=3 t=1 l=1) name(combined, replace)
	graph display combined, xsize(6) ysize(4) scale(1.1)
	graph export "Figure_PredictedValues_Combined.pdf", replace
	
	
		
		
***************************************************
*ROBUSTNESS CHECK MODELS USING COUNT VARIABLE*
***************************************************
*Added several controls from Azpuru (2017) and Azpuru and Boniface (2015)
*efficacy (eff2), insecurity (aoj11), nationalism/pride in the Peruvian political system (b4)

*US MILITARY TRUST
ologit mil3 ustd_dc q2 ses edsc lang urban1 l1 eff2 b12 b4 aoj11 presapproval remit satinfra violence
est store count1
*US GOVERNMENT TRUST
ologit usgovtrust ustd_dc q2 ses edsc lang urban1 l1 eff2 trust_f b4 aoj11 presapproval remit satinfra violence
est store count2
*US INFLUENCE
regress usinfl_peru ustd_dc q2 ses edsc lang urban1 l1 eff2 trust_f aoj11 presapproval remit satinfra violence
est store count3

#delimit ;
	esttab count1 count2 count3 using Table_Count_20170316.tex, replace 
	scalars("ll log-likelihood" "r2 R$^2$")  
	nodep
	bic
	wide
	se(2) 
	b(2) 
	obslast 
	nonumbers
	nomtitles
	eqlabel(none) 
	coeflabel(_cons "\hspace{0.2cm} Constant")
	mgroups("U.S. Military Trust" "U.S. Government Trust" "U.S. Influence", pattern(1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))
	nogaps 
	label
	noomitted
	refcat(ustd_dc "\emph{Key Independent Variables}" q2 "\emph{Demographic Variables}" l1 "\emph{Attitudinal Variables}", nolabel)
	star(* 0.10 ** 0.05 *** 0.01)  
	compress
	order(ustd_dc q2 ses edsc lang urban1 remit eff2 l1 presapproval b12 trust_f b4 aoj11 satinfra _cons)
	nonotes 
	nobaselevels
	addnote("Two-tailed significance tests used." "$*$ p$\leq$ 0.10; $**$ p$\leq$ 0.05; $***$ p$\leq$0.01") 
	;		
	
	#delimit cr
	

	
* Predicted Probability - US Military Trust Y=6 or Y=7

		ologit mil3 c.ustd_dc q2 ses edsc lang urban1 l1 b12 presapproval remit satinfra violence
		
		sum ustd_dc if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_dc=(0 1 2 3) (means) _all lang=0 urban1=1 remit=0) expression(predict(outcome(6))+predict(outcome(7))) level(95) contrast
		
		#delimit ;
			marginsplot, xlabel(0(1)3) recastci(rspike) recast(scatter) 
			ci1opts(lwidth(.3))   
			plot1opts(msym(O) mfcolor() mlwidth(.3))
			xlabel(, notick format(%9.0fc))
			ylabel(, format(%9.2fc))			
			xdimension(ustd_dc)
			xtitle("Deployment Count")
			ytitle("Pr(Very High Trust)")
			legend(off)
			title("")
			subtitle("A" "Trust in US Military")
			xsize(5) ysize(5)	
			scale(1)
			name(panela, replace)
			;
			#delimit cr

* Evaluation differences in marginal effects
		*contrast rb0.ustd_dc, effects

		graph export "Figure_Count_USMilitaryTrust.pdf", replace	
		*graph export "C:\Users\stoyan\Dropbox\Troops and Public Opinion in Latin America\Figures\Figure_Count_USMilitaryTrust.pdf", replace
		
* Predicted Probability - US Government Trust Y=3

		ologit usgovtrust c.ustd_dc q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra violence
		
		sum ustd_dc if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_dc=(0 1 2 3) (means) _all lang=0 urban1=1 remit=0 ) predict(outcome(3)) level(95) contrast
		
		#delimit ;
			marginsplot, xlabel(0(1)3) recastci(rspike) recast(scatter) 
			ci1opts(lwidth(.3))   
			plot1opts(msym(O) mfcolor() mlwidth(.3))
			xlabel(, notick format(%9.0fc)) 
			ylabel(, format(%9.2fc))
			xdimension(ustd_dc)
			xtitle("Deployment Count")
			ytitle("Pr(Very Trustworthy)")
			legend(off)
			title("")
			subtitle("B" "Trust in US Government")
			xsize(5) ysize(5)	
			scale(1)
			name(panelb, replace)
			;
			#delimit cr

* Evaluation differences in marginal effects
		*contrast rb0.ustd_dc, effects
				
		graph export "Figure_Count_USGovernmentTrust.pdf", replace	
		*graph export "C:\Users\stoyan\Dropbox\Troops and Public Opinion in Latin America\Figures\Figure_Count_USGovernmentTrust.pdf", replace		
		
* Predicted Value - US Influence

		reg usinfl_peru c.ustd_dc q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra violence
		
		sum ustd_dc if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_dc=(0 1 2 3) (means) _all lang=0 urban1=1 remit=0 ) predict(xb) level(95) contrast
		
		#delimit ;
			marginsplot, xlabel(0(1)3) recastci(rspike) recast(scatter) 
			ci1opts(lwidth(.3))   
			plot1opts(msym(O) mfcolor() mlwidth(.3))
			xlabel(, notick format(%9.0fc)) 
			ylabel(, format(%9.2fc))
			xdimension(ustd_dc)
			xtitle("Deployment Count")
			ytitle("Assessment of US Influence")
			legend(off)
			title("")
			subtitle("C" "Evaluation of US Influence")
			xsize(5) ysize(5)	
			scale(1)
			name(panelc, replace)
			;
			#delimit cr

			graph export "Figure_Count_USInfluence.pdf", replace	
		*graph export "C:\Users\stoyan\Dropbox\Troops and Public Opinion in Latin America\Figures\Figure_Count_USInfluence.pdf", replace		
		
			
* Evaluation differences in marginal effects
		*contrast rb0.ustd_dc, effects
		
		
* Combine graphs into single figure		
		graph combine panela panelb panelc, cols(3) xsize(6) ysize(3) iscale(.95)
		graph export "Figure_Count_PredictedValues.pdf", replace	
		*graph export "C:\Users\stoyan\Dropbox\Troops and Public Opinion in Latin America\Figures\Figure_Count_PredictedValues.pdf", replace
		
			

/*
*log using "analysis_reportedmodels_2.6.2017.smcl", replace
est table m1* m2* m3*, star(0.01 0.05 0.1) stats(N aic)
*capture log close

*estout m1* m2* m3* using "reportedmodels_2.6.2017.csv", /*
*/ cells(b(fmt(3) star) se(par fmt(3))) stats(N r2 F ll aic) label  /*
*/ starlevels(* 0.1 ** 0.05 *** 0.01)  delimiter(",")

estout m1* m2* m3*, /*
*/ cells(b(fmt(3) star) se(par fmt(3))) stats(N r2 F ll aic) label  /*
*/ starlevels(* 0.1 ** 0.05 *** 0.01)  delimiter("&")

*outtex m1* m2* m3*, detail level below title(Dep = `e(depvar)')
*/
*******************
*ROBUSTNESS CHECKS*
*******************
set more off

****************************************************
*REGIONAL/DEPARTMENT-LEVEL WITH FULL SET OF CONTROLS

*US MILITARY TRUST
ologit mil3 ustd_d q1 q2 ses edsc lang urban1 remit eff2 l1 presapproval b12 iptrust b4 aoj11 sociotrop satmed satedu satinfra violence
est store miltrust_d_full
ologit mil3 ustd_d2 q1 q2 ses edsc lang urban1 remit eff2 l1 presapproval b12 iptrust b4 aoj11 sociotrop satmed satedu satinfra violence
est store miltrust_d2_full
ologit mil3 ustd_d4 q1 q2 ses edsc lang urban1 remit eff2 l1 presapproval b12 iptrust b4 aoj11 sociotrop satmed satedu satinfra violence
est store miltrust_d4_full
ologit mil3 ustd_d6 q1 q2 ses edsc lang urban1 remit eff2 l1 presapproval b12 iptrust b4 aoj11 sociotrop satmed satedu satinfra violence
est store miltrust_d6_full

*US GOVERNMENT TRUST
ologit usgovtrust ustd_d q1 q2 ses edsc lang urban1 remit eff2 l1 presapproval trust_f iptrust b4 aoj11 sociotrop satmed satedu satinfra violence
est store usgovtrust_d_full
ologit usgovtrust ustd_d2 q1 q2 ses edsc lang urban1 remit eff2 l1 presapproval trust_f iptrust b4 aoj11 sociotrop satmed satedu satinfra violence
est store usgovtrust_d2_full
ologit usgovtrust ustd_d4 q1 q2 ses edsc lang urban1 remit eff2 l1 presapproval trust_f iptrust b4 aoj11 sociotrop satmed satedu satinfra violence
est store usgovtrust_d4_full
ologit usgovtrust ustd_d6 q1 q2 ses edsc lang urban1 remit eff2 l1 presapproval trust_f iptrust b4 aoj11 sociotrop satmed satedu satinfra violence
est store usgovtrust_d6_full

*US INFLUENCE
regress usinfl_peru ustd_d q1 q2 ses edsc lang urban1 remit eff2 l1 trust_f presapproval polint aoj11 sociotrop satmed satedu satinfra violence
est store usinfl_d_full
regress usinfl_peru ustd_d2 q1 q2 ses edsc lang urban1 remit eff2 l1 trust_f presapproval polint aoj11 sociotrop satmed satedu satinfra violence
est store usinfl_d2_full
regress usinfl_peru ustd_d4 q1 q2 ses edsc lang urban1 remit eff2 l1 trust_f presapproval polint aoj11 sociotrop satmed satedu satinfra violence
est store usinfl_d4_full
regress usinfl_peru ustd_d6 q1 q2 ses edsc lang urban1 remit eff2 l1 trust_f presapproval polint aoj11 sociotrop satmed satedu satinfra violence
est store usinfl_d6_full

#delimit ;
	esttab miltrust_d_full miltrust_d2_full miltrust_d4_full miltrust_d6_full using Table_Appendix_Regional_Full_1_20180124.tex, replace 
	scalars("ll log-likelihood")  
	nodep
	bic
	wide
	se(2) 
	b(2) 
	obslast 
	nonumbers
	mtitles("1A" "1B" "1C" "1D")
	eqlabel(none) 
	coeflabel(_cons "\hspace{0.2cm} Constant")
	mgroups("Trust in U.S. Military", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))
	nogaps 
	label
	noomitted
	refcat(ustd_d "\emph{Key Independent Variables}" q2 "\emph{Demographic Variables}" l1 "\emph{Attitudinal Variables}", nolabel)
	star(* 0.10 ** 0.05 *** 0.01)  
	compress
	order(ustd_d ustd_d2 ustd_d4 ustd_d6 q2 q1 ses edsc lang urban1 remit eff2 l1 presapproval b12 trust_f iptrust b4 aoj11 sociotrop satmed satedu satinfra _cons)
	nonotes 
	nobaselevels
	addnote("Two-tailed significance tests used." "$*$ p$\leq$ 0.10; $**$ p$\leq$ 0.05; $***$ p$\leq$0.01") 
	;		
	
	#delimit cr


#delimit ;
	esttab usgovtrust_d_full usgovtrust_d2_full usgovtrust_d4_full usgovtrust_d6_full using Table_Appendix_Regional_Full_2_20180124.tex, replace 
	scalars("ll log-likelihood")  
	nodep
	bic
	wide
	se(2) 
	b(2) 
	obslast 
	nonumbers
	mtitles("2A" "2B" "2C" "2D")
	eqlabel(none) 
	coeflabel(_cons "\hspace{0.2cm} Constant")
	mgroups("Trust in U.S. Government", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))
	nogaps 
	label
	noomitted
	refcat(ustd_d "\emph{Key Independent Variables}" q2 "\emph{Demographic Variables}" l1 "\emph{Attitudinal Variables}", nolabel)
	star(* 0.10 ** 0.05 *** 0.01)  
	compress
	order(ustd_d ustd_d2 ustd_d4 ustd_d6 q2 q1 ses edsc lang urban1 remit eff2 l1 presapproval b12 trust_f iptrust b4 aoj11 sociotrop satmed satedu satinfra _cons)
	nonotes 
	nobaselevels
	addnote("Two-tailed significance tests used." "$*$ p$\leq$ 0.10; $**$ p$\leq$ 0.05; $***$ p$\leq$0.01") 
	;		
	
	#delimit cr
	
	
#delimit ;
	esttab usinfl_d_full usinfl_d2_full usinfl_d4_full usinfl_d6_full using Table_Appendix_Regional_Full_3_20180124.tex, replace 
	scalars("r2 R$^2$")  
	nodep
	bic
	wide
	se(2) 
	b(2) 
	obslast 
	nonumbers
	mtitles("3A" "3B" "3C" "3D")
	eqlabel(none) 
	coeflabel(_cons "\hspace{0.2cm} Constant")
	mgroups("Assessment of  U.S. Government", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))
	nogaps 
	label
	noomitted
	refcat(ustd_d "\emph{Key Independent Variables}" q2 "\emph{Demographic Variables}" l1 "\emph{Attitudinal Variables}", nolabel)
	star(* 0.10 ** 0.05 *** 0.01)  
	compress
	order(ustd_d ustd_d2 ustd_d4 ustd_d6 q2 q1 ses edsc lang urban1 remit eff2 l1 presapproval b12 trust_f iptrust b4 aoj11 sociotrop satmed satedu satinfra _cons)
	nonotes 
	nobaselevels
	addnote("Two-tailed significance tests used." "$*$ p$\leq$ 0.10; $**$ p$\leq$ 0.05; $***$ p$\leq$0.01") 
	;		
	
	#delimit cr	
	
*****************************************
*PROVINCE-LEVEL WITH FULL SET OF CONTROLS
cd " "
*cd "C:\Users\stoyan\Dropbox\Troops and Public Opinion in Latin America\Tables"

*US MILITARY TRUST
ologit mil3 ustd_p q1 q2 ses edsc lang urban1 remit eff2 l1 presapproval b12 iptrust b4 aoj11 sociotrop satmed satedu satinfra violence
est store miltrust_p_full
ologit mil3 ustd_p2 q1 q2 ses edsc lang urban1 remit eff2 l1 presapproval b12 iptrust b4 aoj11 sociotrop satmed satedu satinfra violence
est store miltrust_p2_full
ologit mil3 ustd_p6 q1 q2 ses edsc lang urban1 remit eff2 l1 presapproval b12 iptrust b4 aoj11 sociotrop satmed satedu satinfra violence
est store miltrust_p6_full

*US GOVERNMENT TRUST
ologit usgovtrust ustd_p q1 q2 ses edsc lang urban1 remit eff2 l1 presapproval trust_f iptrust b4 aoj11 sociotrop satmed satedu satinfra violence
est store usgovtrust_p_full
ologit usgovtrust ustd_p2 q1 q2 ses edsc lang urban1 remit eff2 l1 presapproval trust_f iptrust b4 aoj11 sociotrop satmed satedu satinfra violence
est store usgovtrust_p2_full
ologit usgovtrust ustd_p6 q1 q2 ses edsc lang urban1 remit eff2 l1 presapproval trust_f iptrust b4 aoj11 sociotrop satmed satedu satinfra violence
est store usgovtrust_p6_full

*US INFLUENCE
regress usinfl_peru ustd_p q1 q2 ses edsc lang urban1 remit eff2 l1 trust_f presapproval polint aoj11 sociotrop satmed satedu satinfra violence
est store usinfl_p_full
regress usinfl_peru ustd_p2 q1 q2 ses edsc lang urban1 remit eff2 l1 trust_f presapproval polint aoj11 sociotrop satmed satedu satinfra violence
est store usinfl_p2_full
regress usinfl_peru ustd_p6 q1 q2 ses edsc lang urban1 remit eff2 l1 trust_f presapproval polint aoj11 sociotrop satmed satedu satinfra violence
est store usinfl_p6_full

#delimit ;
	esttab miltrust_p_full miltrust_p2_full miltrust_p6_full  using Table_Appendix_Province_1_Full_20180124.tex, replace 
	scalars("ll log-likelihood")  
	nodep
	bic
	wide
	se(2) 
	b(2) 
	obslast 
	nonumbers
	mtitles("1A" "1B" "1C" )
	eqlabel(none) 
	coeflabel(_cons "\hspace{0.2cm} Constant")
	mgroups("Trust in U.S. Military", pattern(1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))
	nogaps 
	label
	noomitted
	refcat(ustd_p "\emph{Key Independent Variables}" q2 "\emph{Demographic Variables}" l1 "\emph{Attitudinal Variables}", nolabel)
	star(* 0.10 ** 0.05 *** 0.01)  
	compress
	order(ustd_p ustd_p2 ustd_p6 q2 q1 ses edsc lang urban1 remit eff2 l1 presapproval polint b12 trust_f iptrust b4 aoj11 sociotrop satmed satedu satinfra _cons)
	nonotes 
	nobaselevels
	addnote("Two-tailed significance tests used." "$*$ p$\leq$ 0.10; $**$ p$\leq$ 0.05; $***$ p$\leq$0.01") 
	;		
	#delimit cr

	
	#delimit ;
	esttab usgovtrust_p_full usgovtrust_p2_full usgovtrust_p6_full using Table_Appendix_Province_2_Full_20180124.tex, replace 
	scalars("ll log-likelihood")  
	nodep
	bic
	wide
	se(2) 
	b(2) 
	obslast 
	nonumbers
	mtitles("1A" "1B" "1C" )
	eqlabel(none) 
	coeflabel(_cons "\hspace{0.2cm} Constant")
	mgroups("Trust in U.S. Government", pattern(1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))
	nogaps 
	label
	noomitted
	refcat(ustd_p "\emph{Key Independent Variables}" q2 "\emph{Demographic Variables}" l1 "\emph{Attitudinal Variables}", nolabel)
	star(* 0.10 ** 0.05 *** 0.01)  
	compress
	order(ustd_p ustd_p2 ustd_p6 q2 q1 ses edsc lang urban1 remit eff2 l1 presapproval polint b12 trust_f iptrust b4 aoj11 sociotrop satmed satedu satinfra _cons)
	nonotes 
	nobaselevels
	addnote("Two-tailed significance tests used." "$*$ p$\leq$ 0.10; $**$ p$\leq$ 0.05; $***$ p$\leq$0.01") 
	;		
	#delimit cr
	
	
	#delimit ;
	esttab usinfl_p_full usinfl_p2_full usinfl_p6_full using Table_Appendix_Province_3_Full_20180124.tex, replace 
	scalars("r2 R$^2$")  
	nodep
	wide
	se(2) 
	b(2) 
	obslast 
	nonumbers
	mtitles("1A" "1B" "1C" )
	eqlabel(none) 
	coeflabel(_cons "\hspace{0.2cm} Constant")
	mgroups("Assessment of U.S. Influence", pattern(1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))
	nogaps 
	label
	noomitted
	refcat(ustd_p "\emph{Key Independent Variables}" q2 "\emph{Demographic Variables}" l1 "\emph{Attitudinal Variables}", nolabel)
	star(* 0.10 ** 0.05 *** 0.01)  
	compress
	order(ustd_p ustd_p2 ustd_p6 q2 q1 ses edsc lang urban1 remit eff2 l1 presapproval polint b12 trust_f iptrust b4 aoj11 sociotrop satmed satedu satinfra _cons)
	nonotes 
	nobaselevels
	addnote("Two-tailed significance tests used." "$*$ p$\leq$ 0.10; $**$ p$\leq$ 0.05; $***$ p$\leq$0.01") 
	;		
	#delimit cr
	
	
	
	
******************************************
*MAIN MODELS MINUS LORETO 1998 DEPLOYMENT*
******************************************

foreach var of varlist ustd_d ustd_d2 {
replace `var' = 0 if prov == 1116 
}

*US MILITARY TRUST
ologit mil3 ustd_d q2 ses edsc lang urban1 l1 eff2 b12 b4 aoj11 presapproval remit satinfra violence
est store m1a
ologit mil3 ustd_d2 q2 ses edsc lang urban1 l1 eff2 b12 b4 aoj11 presapproval remit satinfra violence
est store m1b
*IV = COUNT OF DEPLOYMENTS
ologit mil3 ustd_dc q2 ses edsc lang urban1 l1 eff2 b12 b4 aoj11 presapproval remit satinfra violence

*US GOVERNMENT TRUST
ologit usgovtrust ustd_d q2 ses edsc lang urban1 l1 eff2 trust_f b4 aoj11 presapproval remit satinfra violence
est store m2a
ologit usgovtrust ustd_d2 q2 ses edsc lang urban1 l1 eff2 trust_f b4 aoj11 presapproval remit satinfra violence
est store m2b
*IV = COUNT OF DEPLOYMENTS
ologit usgovtrust ustd_dc q2 ses edsc lang urban1 l1 eff2 trust_f b4 aoj11 presapproval remit satinfra violence

*US INFLUENCE
regress usinfl_peru ustd_d q2 ses edsc lang urban1 l1 eff2 trust_f aoj11 presapproval remit satinfra violence
est store m3a
regress usinfl_peru ustd_d2 q2 ses edsc lang urban1 l1 eff2 trust_f aoj11 presapproval remit satinfra violence
est store m3b
*IV = COUNT OF DEPLOYMENTS
regress usinfl_peru ustd_dc q2 ses edsc lang urban1 l1 eff2 trust_f aoj11 presapproval remit satinfra violence

foreach v of varlist * {
	label variable `v' `"\hspace{0.2cm} `: variable label `v''"'
	}
	
#delimit ;
	esttab m1a m1b m2a m2b m3a m3b using Table_NO1998_20180124.tex, replace 
	scalars("ll log-likelihood" "r2 R$^2$")  
	nodep
	bic
	wide
	se(2) 
	b(2) 
	obslast 
	nonumbers
	mtitles("1A" "1B" "2A" "2B" "3A" "3B")
	eqlabel(none) 
	coeflabel(_cons "\hspace{0.2cm} Constant")
	mgroups("U.S. Military Trust" "U.S. Government Trust" "U.S. Influence", pattern(1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))
	nogaps 
	label
	noomitted
	refcat(ustd_d "\emph{Key Independent Variables}" q2 "\emph{Demographic Variables}" l1 "\emph{Attitudinal Variables}", nolabel)
	star(* 0.10 ** 0.05 *** 0.01)  
	compress
	order(ustd_d ustd_d2 q2 ses edsc lang urban1 remit eff2 l1 presapproval b12 trust_f b4 aoj11 satinfra _cons)
	nonotes 
	nobaselevels
	addnote("Two-tailed significance tests used." "$*$ p$\leq$ 0.10; $**$ p$\leq$ 0.05; $***$ p$\leq$0.01") 
	;		
	
	#delimit cr
	

	
* Predicted Probability - US Military Trust Y=7

		ologit mil3 i.ustd_d q2 ses edsc lang urban1 l1 b12 presapproval remit satinfra violence
		
		sum ustd_d if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d=(0 1) (means) _all lang=0 urban1=1 remit=0 ) expression(predict(outcome(6))+predict(outcome(7))) level(95) contrast
		
		#delimit ;
			marginsplot, xlabel(-0.5 " " 0 "No Deployment" .5 " " 1 "Deployment" 1.5 " ") recastci(rspike) recast(scatter) 
			ci1opts(lwidth(.3))   
			plot1opts(msym(O) mfcolor() mlwidth(.3))
			xlabel(, notick format(%9.2fc))
			ylabel(, format(%9.2fc))			
			xdimension(ustd_d)
			xtitle("")
			ytitle("Pr(Very High Trust)")
			legend(off)
			title("")
			subtitle("A" "Trust in US Military")
			xsize(5) ysize(5)	
			scale(1)
			name(panela, replace)
			;
			#delimit cr

			
* Evaluation differences in marginal effects
		contrast rb0.ustd_d, effects

		graph export "Figure_NO1998_USMilitaryTrust.pdf", replace	
		*graph export "C:\Users\stoyan\Dropbox\Troops and Public Opinion in Latin America\Figures\Figure_NO1998_USMilitaryTrust.pdf", replace	
		
		
* Predicted Probability - US Government Trust Y=3

		ologit usgovtrust i.ustd_d q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra violence
		
		sum ustd_d if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d=(0 1) (means) _all lang=0 urban1=1 remit=0 ) predict(outcome(3)) level(95) contrast
		
		#delimit ;
			marginsplot, xlabel(-0.5 " " 0 "No Deployment" .5 " " 1 "Deployment" 1.5 " ") recastci(rspike) recast(scatter) 
			ci1opts(lwidth(.3))   
			plot1opts(msym(O) mfcolor() mlwidth(.3))
			xlabel(, notick format(%9.2fc)) 
			ylabel(, format(%9.2fc))
			xdimension(ustd_d)
			xtitle("")
			ytitle("Pr(Very Trustworthy)")
			legend(off)
			title("")
			subtitle("B" "Trust in US Government")
			xsize(5) ysize(5)	
			scale(1)
			name(panelb, replace)
			;
			#delimit cr

* Evaluation differences in marginal effects
		contrast rb0.ustd_d, effects
				
		graph export "Figure_NO1998_USGovernmentTrust.pdf", replace	
		*graph export "C:\Users\stoyan\Dropbox\Troops and Public Opinion in Latin America\Figures\Figure_NO1998_USGovernmentTrust.pdf", replace	
		
* Predicted Value - US Influence

		reg usinfl_peru i.ustd_d q2 ses edsc lang urban1 l1 trust_f presapproval remit satinfra violence
		
		sum ustd_d if e(sample)
		local min - r(min)
		local max = r(max) 
		local interval = ((`max'-`min')/10)
		margins, at(ustd_d=(0 1) (means) _all lang=0 urban1=1 remit=0 ) predict(xb) level(95) contrast
		
		#delimit ;
			marginsplot, xlabel(-0.5 " " 0 "No Deployment" .5 " " 1 "Deployment" 1.5 " ") recastci(rspike) recast(scatter) 
			ci1opts(lwidth(.3))   
			plot1opts(msym(O) mfcolor() mlwidth(.3))
			xlabel(, notick format(%9.2fc)) 
			ylabel(, format(%9.2fc))
			xdimension(ustd_d)
			xtitle("")
			ytitle("Assessment of US Influence")
			legend(off)
			title("")
			subtitle("C" "Evaluation of US Influence")
			xsize(5) ysize(5)	
			scale(1)
			name(panelc, replace)
			;
			#delimit cr

			graph export "Figure_NO1998_USInfluence.pdf", replace	
		*graph export "C:\Users\stoyan\Dropbox\Troops and Public Opinion in Latin America\Figures\Figure_NO1998_USInfluence.pdf", replace	
		
			
			
* Evaluation differences in marginal effects
		contrast rb0.ustd_d, effects
		
		
* Combine graphs into single figure		
		graph combine panela panelb panelc, cols(3) xsize(6) ysize(3) iscale(.95)
		graph export "Figure_NO1998_PredictedValues.pdf", replace	
	*graph export "C:\Users\stoyan\Dropbox\Troops and Public Opinion in Latin America\Figures\Figure_NO1998_PredictedValues.pdf", replace	
		
*************************
**Correlation between DVs
***************************
	label var mil3 "Trust in U.S. Military"
	label var usgovtrust "Trust in U.S. Government"
	label var usinfl_peru "U.S. Influence in Peru"
	eststo clear	
	estpost correlate mil3 usgovtrust usinfl_peru, matrix
	est store corr_table
	esttab ., unstack b(2) p(2) label
	esttab . using Correlation.tex, unstack b(2) noobs nostar nogaps compress title("Correlation Matrix of Dependent Variables") label nonumber  replace

	corrtex mil3 usgovtrust usinfl_peru, file(Correlation.tex) digits(3) replace title(Dependent Variable Correlation Matrix) tabular
	

	
	
	
*******************************************
*******************************************
************LATINOBAROMETRO 2004***********
*******************************************
*******************************************

*Figures for Appendix

use "Latinobarometro_2004_datos_eng_v2014_06_27.dta", clear

*RECODING OPINION OF THE US
gen opus = .
replace opus = 1 if p70sta==4
replace opus = 2 if p70sta==3
replace opus = 3 if p70sta==2
replace opus = 4 if p70sta==1
label define opuslab 1 "Very Bad" 2 "Bad" 3 "Good" 4 "Very Good"
label values opus opuslab

*DROPPING SPAIN
drop if idenpa==724

************************************************************
*GRAPH OF MEAN OPINION OF THE US IN LATIN AMERICAN COUNTRIES
graph bar (mean) opus, over(idenpa, sort(opus) label(angle(45))) ///
	bargap(-20) bar(1,bcolor(gs8)) legend(off) ///
	yscale(r(1/4) fex) ylabel(0 " " 1 "Very Bad" 2 "Bad" 3 "Good" 4 "Very Good", angle(0) labs(vsmall)) yline(2.758605, lc(black) lp(dash)) ///
	ytitle("Mean Opinion of the U.S., 2004") graphregion(color(white))
graph save "lbmeans_allcountries.gph", replace
graph export "lbmeans_allcountries.pdf", replace

/*
*SCHEME FILES NOT WORKING
graph bar (mean) opus, over(idenpa, sort(opus) label(angle(45))) ///
	bargap(-20) bar(1,bcolor(gs8)) legend(off) ///
	yscale(r(1/4) fex) ylabel(0 " " 1 "Very Bad" 2 "Bad" 3 "Good" 4 "Very Good", angle(0) labs(vsmall)) yline(2.758605, lc(black) lp(dash)) ///
	ytitle("Mean Opinion of the U.S.") title("Opinion of the U.S., 2004") subtitle("in Latin American Countries") ///
	scheme("C:\Users\stoyan\Dropbox\Troops and Public Opinion in Latin America\Analysis\scheme-rbn3mono.scheme") ///
	note("Note: Dashed line is the sample mean; Source: Latinobarometro (2004)") graphregion(color(white))
*/

*PERU ONLY
drop if idenpa!=604

********************************
*GENERATING TROOP DEPLOYMENT GEOGRAPHIC VARIABLES
********************************
*IN THIS DATA, WE LOSE HUANCAVELICA WITH A DEPLOYMENT AND AMAZONAS, APURIMAC, CALLAO, MOQUEGUA, PASCO, AND TUMBES WITHOUT DEPLOYMENTS

gen reg1=.
replace reg1=reg-604000

label define reg1lab 0 "Gran Lima" 2 "Ancash" 4 "Arequipa" 5 "Ayacucho" 6 "Cajamarca" 7 "Cusco" ///
	9 "Huanuco" 10 "Ica" 11 "Junin" 12 "La Libertad" 13 "Lambayeque" 14 "Lima" 15 "Loreto" 19 "Piura" ///
	20 "Puno" 21 "San Martin" 22 "Tacna" 24 "Ucayali"
label values reg1 reg1lab

*DEPARTMENT/REGION DUMMY (1 if U.S. Troops)
gen ustd_d=0
replace ustd_d=1 if reg1==12 | reg1==13 | reg1==14 | reg1==0 | reg1==19 | reg1==10 | reg1==5

*SINCE 2012 DEPARTMENT/REGION DUMMY (1 if U.S. Troops in last 2 years)
gen ustd_d2=0
replace ustd_d2=1 if reg1==10 | reg1==14 | reg1==0

*DEPARTMENT/REGION COUNT
gen ustd_dc=0
replace ustd_dc=1 if reg1==12 | reg1==14 | reg1==19 | reg1==5
replace ustd_dc=3 if reg1==10
replace ustd_dc=4 if reg1==0


****************************************************
*GRAPH OF MEAN OPINION OF THE US IN PERUVIAN REGIONS
graph bar (mean) opus, over(reg1, sort(opus) label(angle(45))) ///
	bargap(-20) bar(1,bcolor(gs8)) legend(off) ///
	yscale(r(1/4) fex) ylabel(0 " " 1 "Very Bad" 2 "Bad" 3 "Good" 4 "Very Good", angle(0) labs(vsmall)) yline(2.884247, lc(black) lp(dash)) ///
	ytitle("Mean Opinion of the U.S., 2004") graphregion(color(white))
graph save "lbmeans_perudept.gph", replace
graph export "lbmeans_perudept.pdf", replace


*********************************************************************************
*GRAPH OF MEAN OPINIONS OF THE US IN PERUVIAN REGIONS WITH AND WITHOUT DEPLOYMENT
cibar opus, over1(ustd_d) level(95) ///
graphopts(ylabel(1 "Very Bad" 2 "Bad" 3 "Good" 4 "Very Good", angle(0) labs(vsmall)) ytitle("Mean Opinion of the U.S., 2004" " ") ysize(4) xsize(4) ///
xlabel(1 "0" 2 ">=1", labs(small)) xtitle("U.S. Troop Deployments, 2006-2012") ///
legend(off) yline(1(1)4, lc(gray)) graphregion(color(white)) ///
plotregion(margin(b = 0 t = 0))) baropts(color(gs8) barwidth(.7)) ///
ciopts(lcolor(black) msize(*5) lw(.5))
graph save "lbbarwithcis_perudept.gph", replace
graph export "lbbarwithcis_perudept.pdf", replace

*DIFFERENCE OF MEANS TEST
su opus if ustd_d==1
*2.907579 
su opus if ustd_d==0
*2.863487 
ttest opus, by(ustd_d)


****************************************************
*CORRELATION BETWEEN OPINION IN 2004 AND DEPLOYMENTS
corr opus ustd_d ustd_d2

**********************************************************************
*REGRESSIONS - OPINION IN 2004 DOES NOT PREDICT SUBSEQUENT DEPLOYMENTS
logit ustd_d opus, cluster(reg1)
logit ustd_d2 opus, cluster(reg1)


	
	

